<template>
  <div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane v-if="showDraftTabs" label="草稿库" name="draft">
        <DraftJournal ref="draft"/>
      </el-tab-pane>

      <el-tab-pane v-if="showOfficialTabs" :showStatus="this.isShow" label="正式库" name="official">
        <OfficialJournal ref="official"/>
      </el-tab-pane>

      <el-tab-pane v-if="showPushTabs" label="推送" name="push">
        <PushJournal ref="push"/>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import DraftJournal from "./DraftJournal"
import OfficialJournal from "./OfficialJournal"
import PushJournal from "./PushJournal";

export default {
  name: "JournalLib",
  components: {
    DraftJournal, OfficialJournal, PushJournal
  },
  data() {
    return {
      activeName: 'draft',
      showDraftTabs: true,
      showOfficialTabs: true,
      showPushTabs: true,
      isShow:''
    };
  },
  methods: {
    handleClick(tab, event) {
      if (tab.name === 'draft') {
        this.$refs.draft.getTableData();
      } else if (tab.name === 'official') {
        this.$refs.official.getTableData();
      } else {
        this.$refs.push.getTableData();
      }
    },
  },
  beforeRouteLeave(to, from, next) {
    // 列表页面跳转到 详情页时，设置不需要缓存
    if (to.name == 'JournalDetail') {
      to.meta.isUseCache = false
    }
    next()
  },
  created() {
    if (this.$store.state.user.userName === 'admin') {
      return
    }
    //角色Id等于管理员角色
    for (let i = 0; i < this.$store.state.user.roleIds.length; i++) {
      if (this.$store.state.user.roleIds[i] === '1455781731549327361') {
        return;
      }
    }
    UTIL.findTreeNode(this.$store.state.menuList, item => {
      if (item.id === this.$store.state.activeId) {
        if (item.editButton || item.detailButton) {
          this.showPushTabs = false
          if (item.editButton && item.detailButton) {
            this.activeName = 'draft'
            this.isShow = 'false'
          } else {
            if (item.detailButton) {
              this.showDraftTabs = false
              this.showPushTabs = false
              this.activeName = 'official'
              this.isShow = "true"
            }
          }
        }
        if (item.editButton && item.pushButton) {
          this.showDraftTabs = true
          this.showOfficialTabs = true
          this.showPushTabs = true
        } else {
          if (item.detailButton && item.pushButton) {
            this.showDraftTabs = false
            this.showOfficialTabs = true
            this.showPushTabs = true
            this.activeName = 'official'
          } else {
            if (item.pushButton) {
              this.showDraftTabs = false
              this.showOfficialTabs = false
              this.activeName = 'push'
            }
          }
        }
      }
    })
  }
}
</script>

<style scoped>

</style>
